package com.wanmait.movie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.wanmait.movie.entity.*;
import com.wanmait.movie.entity.VO.BrandVO;
import com.wanmait.movie.entity.VO.CinemaDetailedVO;
import com.wanmait.movie.entity.VO.CinemaVO;
import com.wanmait.movie.entity.request.manage.cinema.CinemaUpdateRequest;
import com.wanmait.movie.mapper.CinemaMapper;
import com.wanmait.movie.mapper.MovieMapper;
import com.wanmait.movie.service.CinemaService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author 24672
* @description 针对表【movie(电影表)】的数据库操作Service实现
* @createDate 2023-12-15 10:00:43
*/
@Service
public class CinemaServiceImpl extends ServiceImpl<CinemaMapper, Cinema>
    implements CinemaService {
    @Resource
    private CinemaMapper cinemaMapper;
    @Resource
    private MovieMapper movieMapper;

    /**
     * 获取影院信息-分页
     * @param pageNum 页码
     * @param pageSize 条数
     * @return 影院信息
     */
    @Override
    public PageInfo<CinemaVO> getCinemaInfo(Integer pageNum, Integer pageSize) {
        PageMethod.startPage(pageNum, pageSize);
        MPJLambdaWrapper<Cinema> wrapper = new MPJLambdaWrapper<Cinema>()
                .selectAll(Cinema.class)
                .select(Brand::getBrandName)
                .select(Mall::getMName)
                .leftJoin(Brand.class, Brand::getId, Cinema::getBrandId)
                .leftJoin(Mall.class,Mall::getId,Cinema::getMallId);

        return new PageInfo<>(cinemaMapper.selectJoinList(CinemaVO.class, wrapper));
    }

    /**
     * 获取影院信息
     * @return 影院信息
     */
    @Override
    public List<CinemaVO> getCinemaInfo() {
        MPJLambdaWrapper<Cinema> wrapper = new MPJLambdaWrapper<Cinema>()
                .selectAll(Cinema.class)
                .select(Brand::getBrandName)
                .select(Mall::getMName)
                .leftJoin(Brand.class, Brand::getId, Cinema::getBrandId)
                .leftJoin(Mall.class,Mall::getId,Cinema::getMallId);
        return cinemaMapper.selectJoinList(CinemaVO.class, wrapper);
    }

    @Override
    public CinemaDetailedVO getCinemaInfoById(Integer id) {
        MPJLambdaWrapper<Cinema> wrapper = new MPJLambdaWrapper<Cinema>()
                .selectAll(Cinema.class)
                .select(Brand::getBrandName)
                .select(Mall::getMName)
                .leftJoin(Brand.class, Brand::getId, Cinema::getBrandId)
                .leftJoin(Mall.class,Mall::getId,Cinema::getMallId)
                .eq(Cinema::getId,id);

        return cinemaMapper.selectJoinOne(CinemaDetailedVO.class,wrapper);
    }

    @Override
    public BrandVO getBrandInfo() {
     return null;
    }

    @Override
    public Cinema updateCinema(CinemaUpdateRequest cinemaUpdateRequest) {
        return null;
    }

    @Override
    public List<Cinema> getCinemaList() {
        LambdaQueryWrapper<Cinema> queryWrapper = new LambdaQueryWrapper<>();
        return cinemaMapper.selectList(queryWrapper);
    }

    @Override
    public List<Movie> getCinemaMovieList(Cinema cinema) {
        MPJLambdaWrapper<Movie> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Movie.class)
                .leftJoin(Screening.class, Screening::getMovieId, Movie::getId)
                .leftJoin(Lobby.class, Lobby::getId, Screening::getLobbyId)
                .leftJoin(Cinema.class, Cinema::getId, Lobby::getCinemaId)
                .eq(Cinema::getId, cinema.getId())
                .distinct();
        List<Movie> movieList=movieMapper.selectJoinList(Movie.class, queryWrapper);
        return movieList;
    }


}




